package com.lagou.edu.util;

import java.util.Random;

public class CodeUtil {

    /**
     * 生成随机验证码
     *
     * @param bit
     * @return
     */
    public static String generaterRandCode(int bit) {
        String source = "0123456789";
        Random rand = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < bit; i++) {
            sb.append(source.charAt(rand.nextInt(9)) + "");
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        String flag = CodeUtil.generaterRandCode(6);//6是生成6位数验证码
        System.out.println(flag);
    }

}
